import { Injectable } from '@nestjs/common';

import { User, Prisma } from '@prisma/client';
import { PrismaService } from '../common/prisma/prisma.service';
import { MailService } from '@/mail/mail.service';

@Injectable()
export class UsersService {
  // private readonly mailService: MailService;
  constructor(
    private prisma: PrismaService,
    private mailService: MailService,
  ) {}

  async findAll(): Promise<User[]> {
    await this.mailService.sendMail('31', '31', '31');
    return this.prisma.user.findMany();
  }

  async findOne(id: number): Promise<User | null> {
    return this.prisma.user.findUnique({
      where: { id },
    });
  }

  async create(data: Prisma.UserCreateInput): Promise<User> {
    return this.prisma.user.create({
      data,
    });
  }

  async update(id: number, data: Prisma.UserUpdateInput): Promise<User> {
    return this.prisma.user.update({
      where: { id },
      data,
    });
  }

  async remove(id: number): Promise<User> {
    return this.prisma.user.delete({
      where: { id },
    });
  }
}
